package wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 *
 * <KEYIN, VALUEIN>
 * <KEYOUT, VALUEOUT>
 *
 * @author yeq
 */
public class WordCountMapper extends Mapper<LongWritable, Text,Text, IntWritable> {

    Text k = new Text();
    IntWritable v = new IntWritable();


    /**
     * ctrl+o
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //1.转换格式
        String line = value.toString();

        //2.切分数据 globe root
        String[] words = line.split(" ");

        //3.打散 输出成<Key，value>
        for(String word : words){
            k.set(word);
            v.set(1);
            context.write(k,v);
        }





    }
}
